package com.bocai.eelly.net;

import com.bocai.eelly.R;
import com.bocai.eelly.bean.DialogBean;
import com.bocai.eelly.bean.PlaceBean;
import com.bocai.eelly.bean.PortBean;
import com.bocai.eelly.utils.L;
import com.bocai.eelly.utils.T;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.trello.rxlifecycle.components.support.RxFragment;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class ApiManage {
    /**
     * 获取面料类别
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void get_category(final RxFragment rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getFabcirType(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment.getActivity(), R.string.net_error);
                    }
                });
    }
    public static void get_category(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getFabcirType(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }

    /**
     * 获取品牌
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getBrand(final RxFragment rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getBrand(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment.getActivity(), R.string.net_error);
                    }
                });
    }

    /**
     * 获取用途
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getPurpose(final RxFragment rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getPurpose(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment.getActivity(), R.string.net_error);
                    }
                });
    }

    /**
     * 获取运输方式
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getTransportMode(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getTransportMode(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }

    /**
     * 获取贸易方式
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getTradeMode(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getTradeMode(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }

    /**
     * 获取贸易术语
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getMaoyiShuyu(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getMaoyiShuyu(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }

    /**
     * 获取装箱方式
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getZhuangxiangMode(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getZhuangxiangMode(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }

    /**
     * 获取付运费方
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getPayFrieight(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().GETPayFrieight(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }

    /**
     * 获取国家和港口
     * @param rxFragment
     * @param timeline
     * @param sign
     * @param userId
     * @param action1
     */
    public static void getDestionation(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getDestionation(timeline,sign,userId)
                .compose(rxFragment.<PortBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }

    public static void getClothStockType(final RxFragment rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getClothStockTypes(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment.getActivity(), R.string.net_error);
                    }
                });
    }
    public static void getFabricStockType(final RxFragment rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getFabricStockTypes(timeline,sign,userId)
                .compose(rxFragment.<DialogBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment.getActivity(), R.string.net_error);
                    }
                });
    }

    public static void getCity(final RxAppCompatActivity rxFragment, String timeline, String sign, String userId, final Action1 action1){
        new MyRetrofit().getGirlApi().getPlace(timeline,sign,userId)
                .compose(rxFragment.<PlaceBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action1, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        L.d(throwable.toString());
                        T.showShort(rxFragment, R.string.net_error);
                    }
                });
    }
}
